package com.rzico.order.plugin.jd;

import com.rzico.util.HttpUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 京东api接口工具类
 */
public class JDApiUtils {

    /**
     * 刷新token值
     * @return
     */
    public static String refresh_token() {
        String url = "https://bizapi.jd.com/oauth2/refreshToken";
        Map<String, Object> params = new HashMap<String, Object>(6);

        String refresh_token = "uiY5kLQO2z79YMjh7K0kBEVazY1vNRClJyuTrrW5";
        // refresh_token
        params.put("refresh_token", refresh_token);
        // 对接账号
        String clientId="kdaZwD6qYzp23FVER2jf";
        params.put("client_id", clientId);
        // 对接账号密钥
        String clientSecret="591cw7UHDzdNKgKGQPZB";
        params.put("client_secret", clientSecret);
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 3.1-查询京东一级地址列表
     * @param params
     * @return
     */
    public static String getProvince(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/area/getProvince";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 3.2-根据京东一级地址ID，查询京东二级地址列表
     * @param params
     * @return
     */
    public static String getCity(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/area/getCity";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 3.3-根据京东二级地址ID，查询京东三级地址列表
     * @param params
     * @return
     */
    public static String getCounty(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/area/getCounty";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 3.4-根据京东三级地址ID，查询京东四级地址列表
     * @param params
     * @return
     */
    public static String getTown(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/area/getTown";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 3.5-验证已编码为京东一至四级地址ID的有效性
     * @param params
     * @return
     */
    public static String checkArea(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/area/checkArea";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 3.6-根据地址详情转换为京东地址编码。该接口不能保证所有地址都匹配到京东地址，也不能保证所有匹配到的京东地址都正确
     * @param params
     * @return
     */
    public static String getJDAddressFromAddress(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/area/getJDAddressFromAddress";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 4.1-查询商品池编号
     * @param params
     * @return
     */
    public static String getPageNum(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/getPageNum";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.2-查询池内商品编号
     * @param params
     * @return
     */
    public static String getSkuByPage(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/getSkuByPage";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.3-查询商品详情
     * @param params
     * @return
     */
    public static String getDetail(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/getDetail";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.4-查询商品图片
     * @param params
     * @return
     */
    public static String skuImage(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/skuImage";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.5-查询商品的上下架状态
     * @param params
     * @return
     */
    public static String skuState(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/skuState";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.6-查询商品可售性、是否支持专票等影响销售的重要属性
     * @param params
     * @return
     */
    public static String check(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/check";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.7-查询商品在特定区域是否可售
     * @param params
     * @return
     */
    public static String checkAreaLimit(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/checkAreaLimit";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.12根据搜索条件查询符合要求的商品列表
     * @param params
     * @return
     */
    public static String search(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/search/search";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return "搜索商品返回结果="+rs;
    }

    /**
     * 4.13-查询被指定为同一类的商品，如同一款式不同颜色的商品；需要注意符合此条件的商品并不一定被指定为同类商品
     * @param params
     * @return
     */
    public static String getSimilarSku(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/getSimilarSku";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.14-根据分类id查询对应分类信息
     * @param params
     * @return
     */
    public static String getCategory(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/getCategory";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 4.15-查询京东商品一、二、三级分类列表。(该接口获取的都是state=1的有效的分类)
     * @param params
     * @return
     */
    public static String getCategorys(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/product/getCategorys";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 5.1-批量查询商品售卖价。查询在客户商品池中的商品价格，若是（product/check）不可售的商品获取不到价格
     * @param params
     * @return
     */
    public static String getSellPrice(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/price/getSellPrice";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 6.1-批量获取库存接口
     * @param params
     * @return
     */
    public static String getNewStockById(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/stock/getNewStockById";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.1-查询准备提交的订单的运费
     * @param params
     * @return
     */
    public static String getFreight(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/getFreight";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 7.3-提交订单信息，生成京东订单
     * @param params
     * @return
     */
    public static String submitOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/submitOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.4-订单反查接口，根据第三方订单号反查京东的订单号
     * @param params
     * @return
     */
    public static String selectJdOrderIdByThirdOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/selectJdOrderIdByThirdOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.5-确认预占库存订单接口
     * @param params
     * @return
     */
    public static String confirmOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/confirmOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.6-取消未确认订单接口
     * @param params
     * @return
     */
    public static String cancelOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/cancel";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.7-查询京东订单信息接口
     * @param params
     * @return
     */
    public static String selectJdOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/selectJdOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.8-查询配送信息
     * @param params
     * @return
     */
    public static String orderTrack(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/orderTrack";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.9-仅适用于厂商直送订单。厂商直送订单可使用此接口确认收货并将订单置为完成状态
     * @param params
     * @return
     */
    public static String confirmReceived(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/confirmReceived";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.10-更新订单上的PO单号，可选择用于配送单、发票等票面展示
     * @param params
     * @return
     */
    public static String saveOrUpdatePoNo(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/saveOrUpdatePoNo";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.11-查询所有新建的订单列表。可用于核对订单
     * @param params
     * @return
     */
    public static String checkNewOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/checkOrder/checkNewOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.12-查询所有妥投的订单列表。可用于核对订单
     * @param params
     * @return
     */
    public static String checkDlokOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/checkOrder/checkDlokOrder ";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.13-查询所有拒收的订单列表。可用于核对订单
     * @param params
     * @return
     */
    public static String checkRefuseOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/checkOrder/checkRefuseOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 7.14-查询配送预计送达时间
     * @param params
     * @return
     */
    public static String getPromiseTips(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/getPromiseTips";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 8.1-查询金采和预存款余额的余额
     * @param params
     * @return
     */
    public static String getUnionBalance(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/price/getUnionBalance";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 8.2-仅支持预存款余额明细查询，不支持金采余额明细查询
     * @param params
     * @return
     */
    public static String getBalanceDetail(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/price/getBalanceDetail";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 8.3-下单成功支付失败的情况，可以调用此接口重新支付
     * @param params
     * @return
     */
    public static String doPay(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/order/doPay";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.1-校验某订单中某商品是否可以提交售后服务
     * @param params
     * @return
     */
    public static String getAvailableNumberComp(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getAvailableNumberComp";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.2-根据订单号、商品编号查询支持的服务类型
     * @param params
     * @return
     */
    public static String getCustomerExpectComp(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getCustomerExpectComp";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.3-根据订单号、商品编号查询支持的商品返回京东方式
     * @param params
     * @return
     */
    public static String getWareReturnJdComp(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getWareReturnJdComp";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.4-发起售后申请 。
     *
     * 需要该配送单已经妥投。
     * 需要先调用9.1接口校验订单中某商品是否可以提交售后服务
     * 需要先调用9.2接口查询支持的服务类型
     * 需要先调用9.3接口查询支持的商品返回京东方式
     * @param params
     * @return
     */
    public static String createAfsApply(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/createAfsApply";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.5-填写发运信息
     *
     * 如果商品需要逆向发往京东，当选择第三方配送时，使用此接口填写配送信息。
     * 接口依赖：
     * 需要调用9.6 查询得到服务单号
     * 并且有需要补充客户发运信息时调用这个接口
     * @param params
     * @return
     */
    public static String updateSendSku(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/updateSendSku";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.6-查询订单下服务单汇总信息
     * @param params
     * @return
     */
    public static String getServiceListPage(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getServiceListPage";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.7-查询服务单明细信息
     * @param params
     * @return
     */
    public static String getServiceDetailInfo(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getServiceDetailInfo";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.8-取消已经生成的服务单
     * @param params
     * @return
     */
    public static String auditCancel(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/auditCancel";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.9-查询退款信息
     * @param params
     * @return
     */
    public static String getOrderPayByOrderId(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getOrderPayByOrderId";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.10-确认服务单
     * @param params
     * @return
     */
    public static String confirmAfsOrder(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/confirmAfsOrder";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }


    /**
     * 9.11-查询订单下服务单汇总列表信息
     * @param params
     * @return
     */
    public static String getAfsServiceListPag(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/afterSale/getAfsServiceListPage";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.1 申请开票
     * @param params
     * @return
     */
    public static String submitInvoice(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/submit";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.2 查询发票第三方申请单号
     * @param params
     * @return
     */
    public static String queryThrApplyNo(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/queryThrApplyNo";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.3 查询发票概要
     * @param params
     * @return
     */
    public static String selectInvoice(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/select";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.4 查询发票明细
     * @param params
     * @return
     */
    public static String queryInvoiceItem(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/queryInvoiceItem";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.5 查询电子发票明细
     * @param params
     * @return
     */
    public static String getInvoiceList(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/getInvoiceList";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.6 查询发票运单号
     * @param params
     * @return
     */
    public static String invoiceWaybill(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/waybill";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.7 查询发票物流信息
     * @param params
     * @return
     */
    public static String queryInvoiceDeliveryNo(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/queryDeliveryNo";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.8 取消发票申请
     * @param params
     * @return
     */
    public static String invoiceCancel(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/cancel";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 10.9 按发票号查询发票物流信息
     * @param params
     * @return
     */
    public static String queryLogisticsByInvoiceNumber(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/invoice/queryLogisticsByInvoiceNumber";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

    /**
     * 11.1-推送信息接口
     * @param params
     * @return
     */
    public static String getMessage(Map<String, Object> params) {
        String url = "https://bizapi.jd.com/api/message/get";
        // 执行请求
        String rs = HttpUtils.httpPost(url, params);
        return rs;
    }

}
